home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1895 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  880 b 

  1. Path: infoserv.rug.ac.be!news
  2. From: witold.maranda@elis.rug.ac.be (Witold Maranda)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help with gettng 2 chars into an integer!
  5. Date: Wed, 17 Jan 1996 17:51:58 GMT
  6. Organization: University of Ghent
  7. Message-ID: <4djcvd$hu6@infoserv.rug.ac.be>
  8. References: <4d2eh1$7pm@usc.edu>
  9. Reply-To: witold.maranda@elis.rug.ac.be
  10. NNTP-Posting-Host: therm9.elis.rug.ac.be
  11. X-Newsreader: Forte Free Agent 1.0.82
  12.  
  13. wawda@scf.usc.edu (Abu Wawda) wrote:
  14.  
  15. >I want to put into a 2-byte integer. It seems easy at first, but I can't seem 
  16. >to figure out to do it with the bit-fidling operators (shifting or masking). 
  17.  
  18. >    char a,b;
  19. >    int c;
  20.  
  21. >    a = 'A';
  22. >    b = 'B';
  23. >    c = ? /* the first byte in c should contain the value of a, and the 
  24. >                         second byte should contain the value of b */
  25.  
  26. Try this
  27.     c=a;
  28.     c=c<<8;
  29.     c=c+b;
  30. or simply
  31.     c= a<<8 | b;
  32.  
  33.  
  34.  
  35. Witek
  36.  
  37.